//反馈处理
(function() {
  let $modal = $("#issue-edit-modal");
  let $editForm = $("#issue-edit-form");
  let $editSpan = $(".edit-span");
  let $editSubmit = $modal.find("button.submit");

  let initEditForm = function($span, $form) {
    $form.find("input[name=id]").val($span.attr("data-id"));
    $form.find("input.api_title").val($span.attr("data-api_title"));
    $form.find("input.email").val($span.attr("data-email"));
    $form.find("input.qq").val($span.attr("data-qq"));
    $form.find("input.tel").val($span.attr("data-tel"));
    $form.find("textarea.question").val($span.attr("data-question"));
    $form.find("textarea.answer").val($span.attr("data-answer"));
  };

  let verifyEdit = {};

  let fnInitEditReq = () => {
    return new FormData($editForm[0]);
  };

  let fnEditAjax = data => {
    fnUploadAjax(
      "POST",
      "issue/edit?id=" + data.get("id"),
      data,
      "json",
      fnCommonEditSuccess,
      fnCommonEditError
    );
  };

  let fnTrigger = () => {
    $editSpan.click(function() {
      $span = $(this);
      initEditForm($span, $editForm);
    });

    $editSubmit.click(function() {
      let req = fnInitEditReq($editForm);
      if (reqVerify(req, verifyEdit)) {
        fnBtnDisable($(this));
        fnLoading();
        fnEditAjax(req);
      }
    });
  };

  fnTrigger();
})();
